var windowName = "myAddress";
var Page;
apiready = function(){
    onWindowShow(function () {
        console.log(windowName + " show")
        setAddress(getLocData("myAddress"))

        getData()
    })
    onWindowHide(function () {
        console.log(windowName + " hide")
    })
    console.log("index page is OK");
    Page = createVM("#Page",{
        defAddress:{}
        ,list:[]
    },{
        //页面方法
        "init":function () {
        }
        , delAddress: function (id) {
            var data = {
                id:id,
                isDel:1,
                tags:[]
            }
            apiPost("/api/userAddresss", data, function (res, code) {
                if (code == 200) {
                    showToast("更新数据");
                    getData()
                    // gobackDelay()
                }else {
                    showToast(res.message);
                }
            });

        }
        , setDefault: function (id) {
            apiGet("/app/set/my/default/address/"+id,{},function (res , code) {
                if (code == 200) {
                    getData()
                }showToast(res.message)
            })
        }

    })
    Page.init()
}

function getData() {
    apiGet("/api/userAddresss", {}, function (res, code) {
        if (code == 200) {
            setAddress(res.data)
            // showToast(res.message);
        }else {

        }
        logJson(res,"/app/my/address_: ");
    });
}

function setAddress(data) {
    if (isTrue(data)) {
        setLocData('myAddress',data)
        //设置默认数据
        var defAddress = data[0];
        Page.defAddress = defAddress;
        var list = arrayDelIndex(data,0);
        //设置其他数据
        if(isTrue(list)){
            Page.list = list
        }else {
            Page.list = []
        }
    }
}